package com.whiliong.jxc.action.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

import com.whlilong.jxc.db.DbManager;
import com.whlilong.jxc.sys.SaveLogInfo;
import com.whlilong.jxc.util.FileUtil;

public class InitialHandler extends AbstractHandler implements IHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		// TODO Auto-generated method stub
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		if (SaveLogInfo.getInstance().getUsertag().endsWith("0"))
			if (MessageDialog.openConfirm(window.getShell(), "友情提示",
					"开业清仓将对数据库中的数据进行清除，确定吗？")) {
				DbManager.getInstance().create(
						FileUtil.readTxt(FileUtil.getWorkspace()
								+ "sql.txt", ""));
				MessageDialog.openInformation(window.getShell(), "清仓成功", "开业清仓成功！");
			} else {
				MessageDialog
						.openInformation(window.getShell(), "清仓失败", "放弃开业清仓操作！");
			}
		else {
			MessageDialog.openInformation(window.getShell(), "权限限制", "没有该权限！");
		}
		return null;
	}

}
